/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package bpmlab.shift.bean;

import bpmlab.shift.dao.DAOException;
import bpmlab.shift.dao.DAOFactory;
import bpmlab.shift.dao.service.CardapioDAO;
import bpmlab.shift.entity.Cardapio;
import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

/**
 *
 * @author Mikael Lima
 */
@ManagedBean
@RequestScoped
public class CardapioBean implements Serializable {

    private final CardapioDAO dao = DAOFactory.criarCardapioDAO();
    private Cardapio cardapio = new Cardapio();
    private List<Cardapio> cardapios;

    public String salvar() {
        try {
            dao.salvar(cardapio);
            JsfUtil.mensagemSalvoComSucesso();
            return "/admin/cardapio/lista-cardapio.xhtml";
        } catch (DAOException ex) {
            JsfUtil.mensagemErroAoSalvar();
            return null;
        }
    }

    public void excluir() {
        try {
            dao.excluir(cardapio);
            JsfUtil.mensagemRemovidoComSucesso();
        } catch (DAOException ex) {
            JsfUtil.mensagemErroAoRemover();
        }
    }
    
    public Cardapio getCardapio() {
        return cardapio;
    }

    public void setCardapio(Cardapio cardapio) {
        this.cardapio = cardapio;
    }

    public List<Cardapio> getCardapios() {
        cardapios = dao.obterTodosComItens();
        return cardapios;
    }
    
}
